home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12477 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Passing Function Pointers
  5. Date: 31 Mar 1996 22:24:03 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4jn0m3$1ae@sparcserver.lrz-muenchen.de>
  9. References: <315E7284.479F@sooner.net>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. Eddie Bush <edwbush@sooner.net> writes:
  13.  
  14. [He wants to pass a callback function to a delete function for nodes
  15. in a list]
  16.  
  17. >I have used this technique under UN*X platforms using gcc to compile, and 
  18. >it works just fine.  It has been a while since I've done it though, so I 
  19. >am thinking that maybe it is not just perfectly correct or something.  
  20. >Anyhow, here it is:
  21.  
  22. >void delete (list *my_list, int *fn){
  23. >  
  24. >  l_node temp_node = (*my_list) -> head;
  25. >  
  26. >  if (!is_empty(*my_list)){
  27. >    (*my_list) -> head = (*my_list) -> head -> next;
  28. >    (*my_list) -> head -> pre = NULL;
  29. >  }
  30. >  (*fn) (temp_node);
  31.  
  32.   fn is a pointer to int. *fn is an int, i.e. _not_ a function so
  33.   if your compiler tells you that you are calling a non-function,
  34.   why don't you trust it?
  35.  
  36. >  free (temp_node);
  37. >}
  38.  
  39. >I made *fn an int because it didn't like the void, and now instead of 
  40. >complaining about that it complains about - well, here's the error 
  41. >message:
  42.  
  43. >Error LIST.H 71:  Call to nonfunction.
  44.  
  45. >Any ideas?  It isn't 'clicking' for me.  Is this something to do with the 
  46. >version (Borland C/C++ 3.0) I am running maybe?  I passed pointers to 
  47. >functions fine using the gcc compiler!
  48.  
  49. Well, all versions of gcc available to me do not allow calling an
  50. int as a function. Are you abolutely sure that your functions 
  51. signature did not look suspiciously similar to
  52.  
  53.    void delete (list *my_list, int (*fn)(l_node));
  54.  
  55. Hint: If you make claims about a certain compiler, be sure it is
  56. Frolic C, available on the Frozzietec CD 6400 only. Otherwise, there
  57. might be someone reading your article who has access to that compiler.
  58.  
  59. Kurt
  60. -- 
  61. | Kurt Watzka                             Phone : +49-89-2180-6254
  62. | watzka@stat.uni-muenchen.de
  63.